package com.wjbgn.electronicnian.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.electronicnian.dto.NianDumplingsDTO;
import com.wjbgn.electronicnian.entity.NianDumplingsDO;
import com.wjbgn.electronicnian.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 
 * Create Date: 2022-01-20T11:06:12.872423800
 * @author weirx
 * @version 1.0
 */
@Component
public class NianDumplingsDoConvert {

    /**
     * DtoToDo
     *
     * @param nianDumplingsDTO
     * @return
     */
    public static NianDumplingsDO dtoToDo(NianDumplingsDTO nianDumplingsDTO) {
            NianDumplingsDO nianDumplingsDO = new NianDumplingsDO();
        BeanCopierUtil.copy(nianDumplingsDTO, nianDumplingsDO);
        return nianDumplingsDO;
    }

    /**
     * DoToDto
     *
     * @param nianDumplingsDO
     * @return
     */
    public static NianDumplingsDTO doToDto(NianDumplingsDO nianDumplingsDO) {
            NianDumplingsDTO nianDumplingsDTO = new NianDumplingsDTO();
        BeanCopierUtil.copy(nianDumplingsDO, nianDumplingsDTO);
        return nianDumplingsDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<NianDumplingsDTO> pageConvert(Page<NianDumplingsDO> pageDO) {
        List<NianDumplingsDTO> list = listConvert(pageDO.getRecords());
        Page<NianDumplingsDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<NianDumplingsDTO> listConvert(List<NianDumplingsDO> listDO) {
        List<NianDumplingsDTO> list = new ArrayList<>();
            NianDumplingsDTO nianDumplingsDTO;
        for (NianDumplingsDO nianDumplingsDO : listDO) {
                nianDumplingsDTO = new NianDumplingsDTO();
            BeanCopierUtil.copy(nianDumplingsDO, nianDumplingsDTO);
            list.add(nianDumplingsDTO);
        }
        return list;
    }
}